import HDataTable from "@/components/ant-ext-table/HDataTable";
import {DeleteOutlined, PlusSquareOutlined} from "@ant-design/icons";
import HAction from "@/components/common/HAction";
import React from "react";
import {HDataTableSlice} from "@/components/ant-ext-table/redux/dataTableSlice";
import {Dispatch} from "redux";
import {HTableProps} from "@/components/ant-ext-table/HTable";
import {useDispatch} from "react-redux";
import FeeListEdit from "@/pages/m-fee-list/edit";
import EntityFeeList from "@/api/entity-fee-list";

function getColumns(dispatch: Dispatch): HTableProps<any>["columns"] {
    return [
        {
            title: "ID",
            dataIndex: 'id',
            width: '200px',
            fixed: 'left',
        }, {
            title: "金额线(当前金额与小一档金额之间的收费标准)",
            dataIndex: 'amount',
            render: (value, record) => {
                return <HAction type={"link"}
                                empower={EntityFeeList.EDIT}
                                invalid
                                action={() => dispatch!(HDataTableSlice.actions.doAction({
                                    action: EntityFeeList.EDIT,
                                    rowKey: EntityFeeList.RowKey,
                                    row: record
                                }))}
                                children={value}/>
            }
        }, {
            title: "收费",
            dataIndex: 'fee',
        }, {
            title: "返现",
            dataIndex: 'cashback',
        }
    ]
}

export default function Index() {
    const dispatch = useDispatch()

    return <>
        <FeeListEdit/>
        <HDataTable
            option={[
                {key: EntityFeeList.ADD, title: "新增", icon: <PlusSquareOutlined/>},
                {
                    key: EntityFeeList.DEL,
                    title: "删除",
                    mode: "multi",
                    icon: <DeleteOutlined style={{color: "red"}}/>,
                    confirm: "是否要删除所选数据",
                    action: (data) => {
                        EntityFeeList.delete({
                            body: {idList: data.selectRowKeys},
                            success: () => dispatch(HDataTableSlice.actions.setQueryParams({}))
                        })
                    }
                },
            ]}
            columns={getColumns(dispatch)} selectMethod={EntityFeeList.selectTablePage}
            rowKey={"id"}
        />
    </>
}